<?php
include_once('Publication.php');
include_once('testHack.php');

if(isset($_GET['authorID'])) {

    
    $authorID = $_GET['authorID'];
    
    $keywordArray = array("west virginia", "wvu", "wv", "morgantown");
    $IEEEpaperArray = array();
    $notInRepos = array();
    $allGroups;
    
    $pub = new Publication;
    
    $pub->authorID = $authorID;
    
    $i = 0;
    $max = 101;
    
    do {
    $pub->starIdx = 1 + $i;
    $pub->endIdx = 100 + $i;
    
    $pub->makeQuery();
    $max =  $pub->getPublicationCount();
    
    $paperArray = $pub->getPaperObj();
    
    foreach ($paperArray as $paper)
    {
        foreach ($paper->urlArray as $url)
        {
            if (stripos($url, 'arnumber'))
            {
                $paper->arnumber = findARnumber($url);
                break;
            }
        }
        if ($paper->arnumber != '0')
        {
            array_push($IEEEpaperArray, $paper);
        }
        else 
        {
            array_push($notInRepos, $paper);
        }
        
        
    }
    $i+=100;
    } while ($i < $max);
    
    $allGroups = new returnObj;
    $allGroups = labelPapers($IEEEpaperArray, $keywordArray);
    $allGroups->notInRepos = $notInRepos;
    echo json_encode($allGroups);
    
    //echo count($IEEEpaperArray);
 
}  

function findARnumber($url)
{
    $splitArray = explode('arnumber=',$url);
    return $splitArray[1];
}



?>